# class Solution(object):
#     def findTheWinner(self, n, k):
#         """
#         :type n: int
#         :type k: int
#         :rtype: int
#         """
#         l = [i for i in range(n)]
#         index = 0
#         for i in range(n - 1):
#             del_index = (index + k - 1) % (n - i)
#             del l[del_index]
#             index = del_index % (n - i - 1)
#         return l[index] + 1

# 约瑟夫环
class Solution(object):
    def findTheWinner(self, n, k):
        """
        :type n: int
        :type k: int
        :rtype: int
        """
        pos = 0
        for i in range(n):
            pos = (pos + k) % (i + 1)
        return pos + 1


data = Solution()
n = 5
k = 2
print(data.findTheWinner(n, k))





